package com.ict.common;

import java.io.*;

public class LogUtils {
    public static void LogWriteBase(File file,String str){
        FileWriter fileWriter=null;
        try{
            fileWriter=new FileWriter(file);
            fileWriter.write(str);
            fileWriter.close();
        }catch (IOException e){
            if (fileWriter!=null){
                try{
                    fileWriter.close();
                }catch (IOException e2){
                    System.out.println("输入流关闭失败："+e2);
                }
            }
        }
    }

    public static void LogWriteAppend(String filePath,String str){
        FileWriter fw=null;
        BufferedWriter bw=null;
        try {
            fw = new FileWriter(filePath, true);
            bw = new BufferedWriter(fw);
//            bw.append("在已有的基础上添加字符串");
            bw.write(str+"\r\n ");// 往已有的文件上添加字符串
            bw.close();
            fw.close();
        } catch (Exception e) {
            if (fw!=null){
                try {
                    fw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (bw!=null){
                try {
                    bw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }

//    public static void main(String[] args) {
//        String filepath="E:\\AisPos\\logs\\testLog.log";
//        String str="today is 2018.2.9";
//        LogWriteAppend(filepath,str);
//        String str2="test by chenlong";
//        LogWriteAppend(filepath,str2);
//    }
}
